home *** CD-ROM | disk | FTP | other *** search
- VERSION 2.00
- Begin Form DevForm
- Caption = "Device Tester"
- ClientHeight = 4080
- ClientLeft = 1095
- ClientTop = 1485
- ClientWidth = 7365
- Height = 4485
- Left = 1035
- LinkTopic = "Form1"
- ScaleHeight = 4080
- ScaleWidth = 7365
- Top = 1140
- Width = 7485
- Begin CommandButton Command1
- Caption = "&Set as Default"
- Height = 375
- Left = 600
- TabIndex = 3
- Top = 3000
- Width = 1815
- End
- Begin ListBox List1
- Height = 2565
- Left = 600
- TabIndex = 0
- Top = 240
- Width = 5175
- End
- Begin Label Label2
- AutoSize = -1 'True
- Height = 195
- Left = 1440
- TabIndex = 2
- Top = 3600
- Width = 75
- End
- Begin Label Label1
- Caption = "Default:"
- Height = 255
- Left = 600
- TabIndex = 1
- Top = 3600
- Width = 735
- End
- DefInt A-Z
- ' Windows API Functions
- Declare Function GetProfileString Lib "Kernel" (ByVal AppName$, ByVal KeyName As Any, ByVal Default$, ByVal ReturnedString$, ByVal nSize%)
- Declare Function WriteProfileString Lib "Kernel" (ByVal AppName$, ByVal KeyName$, ByVal lpString$)
- Declare Function PostMessageByString Lib "User" Alias "PostMessage" (ByVal hWnd%, ByVal wMsg%, ByVal wParam%, ByVal lParam$)
- ' Windows API Constants
- Const HWND_BROADCAST = &HFFFF
- Const WM_WININICHANGE = &H1A
- ' Device Arrays
- Dim DeviceInfo$()
- Dim DeviceList$()
- Dim DeviceName$()
- Sub Command1_Click ()
- ' Call sub to set new Default Device
- SetNewDefault
- ' Call sub to Get Default Device
- GetDefault
- End Sub
- Sub Form_Load ()
- ' Call sub to Get Default Device
- GetDefault
- ' Call sub to Get Device List
- GetDevices
- ' Start with First Item on List
- List1.ListIndex = 0
- End Sub
- Sub Form_Resize ()
- ' Call sub to Get Default Device
- GetDefault
- End Sub
- Sub GetDefault ()
- 'Determine Default Device
- Section$ = "windows"
- Key$ = "device"
- RetVal$ = String$(255, 0)
- ErrCode = GetProfileString(Section$, Key$, "", RetVal$, Len(RetVal$))
- RetVal$ = Left$(RetVal$, InStr(RetVal$, Chr$(0)) - 1)
- Label2.Caption = Left$(RetVal$, InStr(RetVal$, ",") - 1) + " on " + Mid$(Mid$(RetVal$, InStr(RetVal$, ",") + 1), InStr(Mid$(RetVal$, InStr(RetVal$, ",") + 1), ",") + 1)
- End Sub
- Sub GetDevices ()
- ' Find Devices Installed
- DeviceCount = 0
- Section$ = "devices"
- Key$ = ""
- RetVal$ = String$(4096, 0)
- ErrCode = GetProfileString(Section$, 0&, "", RetVal$, Len(RetVal$))
- LastNull = 0
- If ErrCode <> 0 Then
- Do
-
- ' Get Device's name as seen by user
- NameOfDevice$ = Left$(RetVal$, InStr(RetVal$, Chr$(0)) - 1)
- RetVal$ = Mid$(RetVal$, InStr(RetVal$, Chr$(0)) + 1)
-
- ' Get Device's Internal Name and Connection Information
- ReturnedString$ = String$(255, 0)
- ErrCode = GetProfileString(Section$, NameOfDevice$, "", ReturnedString$, Len(ReturnedString$))
- InternalName$ = Left$(ReturnedString$, InStr(ReturnedString$, ",") - 1)
- ConnectionInfo$ = Mid$(ReturnedString$, InStr(ReturnedString$, ",") + 1)
- ' Parse out connection list and add to ListBox
- Do
- If InStr(ConnectionInfo$, ",") Then
- ConnectToAdd$ = Left$(ConnectionInfo$, InStr(ConnectionInfo$, ",") - 1)
- ConnectionInfo$ = Mid$(ConnectionInfo$, InStr(ConnectionInfo$, ",") + 1)
- NoMoreToFind = False
- Else
- ConnectToAdd$ = Left$(ConnectionInfo$, InStr(ConnectionInfo$, Chr$(0)) - 1)
- NoMoreToFind = True
- End If
- DeviceCount = DeviceCount + 1
- ReDim Preserve DeviceList$(DeviceCount)
- DeviceList$(DeviceCount) = NameOfDevice$
- ReDim Preserve DeviceName$(DeviceCount)
- DeviceName$(DeviceCount) = InternalName$
- ReDim Preserve DeviceInfo$(DeviceCount)
- DeviceInfo$(DeviceCount) = ConnectToAdd$
- List1.AddItem DeviceList$(DeviceCount) + " on " + DeviceInfo$(DeviceCount)
- Loop Until NoMoreToFind
- LastNull = InStr(RetVal$, Chr$(0))
- Loop Until LastNull = 1 ' 1 indicates that 1st position is a null, no more entries
- End If
- RetVal$ = ""
- ReturnedString$ = ""
- End Sub
- Sub SetNewDefault ()
- ' Get Name and Full Info of New Default Device from List Box
- NewDevice$ = DeviceList$(List1.ListIndex + 1) + "," + DeviceName$(List1.ListIndex + 1) + "," + DeviceInfo$(List1.ListIndex + 1)
- ' Update Win.INI and send BroadCast changes
- ErrCode = WriteProfileString("windows", "device", NewDevice$)
- ErrCode = PostMessageByString(HWND_BROADCAST, WM_WININICHANGE, 0, "windows")
- End Sub
-